package com.heima.user.controller.v1;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.user.dtos.ExamineUserDto;
import com.heima.model.user.pojos.ApUserRealname;
import com.heima.user.service.UserRealNameService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/api/v1/auth")
public class UserAdminController {
    @Autowired
    private UserRealNameService userRealNameService;

    @PostMapping("/list")
    ResponseResult list(@RequestBody ExamineUserDto dto) {
        Page page = new Page(dto.getPage(), dto.getSize());
        LambdaQueryWrapper<ApUserRealname> wrapper = new LambdaQueryWrapper<>();
        if (dto.getStatus() != null) {
            wrapper.eq(ApUserRealname::getStatus, dto.getStatus());
        }
        Page result = userRealNameService.page(page, wrapper);

        ResponseResult responseResult = new PageResponseResult(dto.getPage(), dto.getSize(), (int) result.getTotal());
        responseResult.setData(result.getRecords());
        return responseResult;
    }

    @PostMapping("/authFail")
    ResponseResult authFail(@RequestBody ExamineUserDto dto) {
        ApUserRealname user = new ApUserRealname();
        user.setId(dto.getId());
        user.setStatus((short) 2);
        user.setReason(dto.getMsg());
        userRealNameService.updateById(user);
        return ResponseResult.okResult("操作成功");
    }

    @PostMapping("/authPass")
    ResponseResult authPass(@RequestBody ExamineUserDto dto) {
        ApUserRealname user = new ApUserRealname();
        user.setId(dto.getId());
        user.setStatus((short) 9);
        userRealNameService.updateById(user);
        return ResponseResult.okResult("操作成功");
    }

}
